Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@swan-io/request
Advanced tools
Wrapper for XMLHttpRequest with better data-structures
$ yarn add @swan-io/request @swan-io/boxed
# --- or ---
$ npm install --save @swan-io/request @swan-io/boxed
Future
, Result
& Option
)Future
APIonLoadStart
& onProgress
eventsresponseType
import { Request, badStatusToError, emptyToError } from "@swan-io/request";
// Regular case
Request.make({ url: "/api/health" }).onResolve(console.log);
// Result.Ok({status: 200, ok: true, response: Option.Some("{\"ok\":true}")})
// Timeout
Request.make({ url: "/api/health", timeout: 2000 }).onResolve(console.log);
// Result.Error(TimeoutError)
// Network error
Request.make({ url: "/api/health" }).onResolve(console.log);
// Result.Error(NetworkError)
// Custom response type
Request.make({ url: "/api/health", responseType: "json" }).onResolve(
console.log,
);
// Result.Ok({status: 200, ok: true, response: Option.Some({ok: true})})
// Handle empty response as an error
Request.make({ url: "/api/health" })
.mapOkToResult(emptyToError)
.onResolve(console.log);
// Result.Error(EmptyResponseError)
// Handle bad status as an error
Request.make({ url: "/api/health" })
.mapOkToResult(badStatusToError)
.onResolve(console.log);
// Result.Error(BadStatusError)
// Cancel request
useEffect(() => {
const future = Request.make({ url: "/api/health" });
return () => future.cancel();
}, []);
url
: stringmethod
: GET
(default), POST
, OPTIONS
, PATCH
, PUT
or DELETE
responseType
:
text
: (default) response will be a string
arraybuffer
: response will be a ArrayBuffer
document
: response will be Document
blob
: response will be Blob
json
: response will be a JSON valuebody
: request bodyheaders
: a record containing the headerswithCredentials
: booleanonLoadStart
: event triggered on load startonProgress
: event triggered at different times when the payload is being senttimeout
: numberReturns a Future<Result<Response<T>, NetworkError | TimeoutError>>
, where Response<T>
has the following properties:
status
: number
ok
: boolean
response
: Option<T>
xhr
: XMLHttpRequest
T
is the type associated with the responseType
provided in the config
object.
Helper to use with mapOkToResult
to consider empty response as an error.
Helper to use with mapOkToResult
to consider a status outside of the 200-299 range as an error.
FAQs
Wrapper for XMLHttpRequest with better data-structures
We found that @swan-io/request demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.